/**
 * Created by FDG282 on 2017/11/13.
 */

function G(id) {
    return document.getElementById(id);
}
/*function mapShow(id,endstr,inputId,searchList,sureBtn){
 var map = new BMap.Map(id);
 map.centerAndZoom(endstr,19);
 var ac = new BMap.Autocomplete({
 "input" : inputId,
 "location" : id
 });
 ac.addEventListener('onhighlight',function(e){
 var str = "";
 var _value = e.fromitem.value;
 var value = "";
 if (e.fromitem.index > -1) {
 value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
 }
 str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

 value = "";
 if (e.toitem.index > -1) {
 _value = e.toitem.value;
 value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
 }
 str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
 G(searchList).innerHTML = str;
 });
 var myValue;
 ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
 var _value = e.item.value;
 myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
 G(searchList).innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;

 setPlace();
 });
 function setPlace() {
 map.clearOverlays();    //清除地图上所有覆盖物
 function myFun() {
 var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
 map.centerAndZoom(pp, 18);
 map.addOverlay(new BMap.Marker(pp));    //添加标注
 }

 var local = new BMap.LocalSearch(map, { //智能搜索
 onSearchComplete: myFun
 });
 local.search(myValue);
 var start = myValue;
 var end = endstr;
 var routePolicy = [BMAP_DRIVING_POLICY_LEAST_TIME, BMAP_DRIVING_POLICY_LEAST_DISTANCE, BMAP_DRIVING_POLICY_AVOID_HIGHWAYS];
 sureBtn.click(function () {
 map.clearOverlays();
 var i = myValue;
 search(start, end, routePolicy[i]);
 function search(start, end, route) {
 var driving = new BMap.DrivingRoute(map, {renderOptions: {map: map, autoViewport: true}, policy: route});
 driving.search(start, end);
 }
 });
 }

 }
 mapShow(G('1-map'),"上海市闵行区剪刀石头布家居生活广场",G('suggestId'),G('searchResultPanel'),G('js_s'));
 mapShow(G('2-map'),"上海市浦东新区剪刀石头布家居生活广场",G('suggestId2'),G('searchResultPanel2'),G('js_s2'));*/
// 吴中店
function wz(){
    var map = new BMap.Map("l-map");
    map.centerAndZoom("上海市闵行区剪刀石头布家居生活广场",19);// 初始化地图,设置城市和地图级别。
    map.enableScrollWheelZoom();
    /*add FDG416 2018/1/17 ID457 【商城需求】地图上增加标示：剪刀石头布公司的位置图标 start*/ 
    var point = new BMap.Point(121.386663,31.180215);
    // 创建标注
    var marker = new BMap.Marker(point);  
    //把标注添加到地图上
    map.addOverlay(marker);
    //跳动的动画
    marker.setAnimation(BMAP_ANIMATION_BOUNCE); 
    /*add FDG416 2018/1/17 ID457 【商城需求】地图上增加标示：剪刀石头布公司的位置图标 end*/ 
    var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
        {"input" : "suggestId"
            ,"location" : map
        });
    ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
        var str = "";
        var _value = e.fromitem.value;
        var value = "";
        if (e.fromitem.index > -1) {
            value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
        }
        str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

        value = "";
        if (e.toitem.index > -1) {
            _value = e.toitem.value;
            value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
        }
        str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
        G("searchResultPanel").innerHTML = str;
    });

    var myValue;
    ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
        var _value = e.item.value;
        myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
        G("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
        setPlace();
    });
    function setPlace(){
        map.clearOverlays();    //清除地图上所有覆盖物
        function myFun(){
            var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
            map.centerAndZoom(pp, 18);
            map.addOverlay(new BMap.Marker(pp));    //添加标注
        }
        var local = new BMap.LocalSearch(map, { //智能搜索
            onSearchComplete: myFun
        });
        local.search(myValue);
        var start = myValue;
        var end = "上海市闵行区剪刀石头布家居生活广场";
        var routePolicy = [BMAP_DRIVING_POLICY_LEAST_TIME,BMAP_DRIVING_POLICY_LEAST_DISTANCE,BMAP_DRIVING_POLICY_AVOID_HIGHWAYS];
        $("#js_s").click(function(){
            map.clearOverlays();
            var i=myValue;
            search(start,end,routePolicy[i]);
            function search(start,end,route){
                var driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true},policy: route});
                driving.search(start,end);
            }
        });
    }
}
//浦东店
function pd(){
    var map2 = new BMap.Map("2-map");
    map2.centerAndZoom(new BMap.Point(121.525541,31.206837), 18);
    //map2.centerAndZoom("上海市浦东新区上海剪刀石头布家居实业有限公司(浦东店)",19);// 初始化地图,设置城市和地图级别。
    map2.enableScrollWheelZoom();
    /*add FDG416 2018/1/17 ID457 【商城需求】地图上增加标示：剪刀石头布公司的位置图标 start*/ 
    var point2 = new BMap.Point(121.528608,31.205622);
    // 创建标注
    var marker2 = new BMap.Marker(point2);  
    //把标注添加到地图上
    map2.addOverlay(marker2);
    //跳动的动画
    marker2.setAnimation(BMAP_ANIMATION_BOUNCE); 
    /*add FDG416 2018/1/17 ID457 【商城需求】地图上增加标示：剪刀石头布公司的位置图标 end*/ 
    var ac2 = new BMap.Autocomplete(    //建立一个自动完成的对象
        {"input" : "suggestId2"
            ,"location" : map2
        });
    ac2.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
        var str = "";
        var _value = e.fromitem.value;
        var value = "";
        if (e.fromitem.index > -1) {
            value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
        }
        str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

        value = "";
        if (e.toitem.index > -1) {
            _value = e.toitem.value;
            value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
        }
        str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
        G("searchResultPanel2").innerHTML = str;
    });

    var myValue2;
    ac2.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
        var _value = e.item.value;
        myValue2 = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
        G("searchResultPanel2").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue2 = " + myValue2;

        setPlace2();
    });
    function setPlace2(){
        map2.clearOverlays();    //清除地图上所有覆盖物
        function myFun(){
            var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
            map2.centerAndZoom(pp, 18);
            map2.addOverlay(new BMap.Marker(pp));    //添加标注
        }
        var local = new BMap.LocalSearch(map2, { //智能搜索
            onSearchComplete: myFun
        });
        local.search(myValue2);
        var start = myValue2;
        var end = "上海市浦东新区上海剪刀石头布家居实业有限公司(浦东店)";
        var routePolicy = [BMAP_DRIVING_POLICY_LEAST_TIME,BMAP_DRIVING_POLICY_LEAST_DISTANCE,BMAP_DRIVING_POLICY_AVOID_HIGHWAYS];
        $("#js_s2").click(function(){
            map2.clearOverlays();
            var i2=myValue2;
            search(start,end,routePolicy[i2]);
            function search(start,end,route){
                var driving = new BMap.DrivingRoute(map2, {renderOptions:{map: map2, autoViewport: true},policy: route});
                driving.search(start,end);
            }
        });
    }

}
wz();
pd();
$('.fraffic_title .item').on('click',function(){
    var _index = $(this).index();
    $(this).addClass('title_active').siblings('.item').removeClass('title_active');
    $('.fraffic_content').eq(_index).show().siblings('.fraffic_content').hide();
});